﻿/// <reference path="../jquery-1.5.1.min.js" />
/// <reference path="../jquery-ui-1.8.11.min.js" />


var linkObj;

$(document).ready(function () {

    $('#dprDialogDiv').dialog({
        autoOpen: false,
        width: "auto",
        //show: { effect: 'fadein', duration: 500 },
        //hide: { effect: 'fadeout', duration: 500 },
        resizable: false,
        modal: true,
        buttons: {
            Submit: function () {
                $("#update-message").html(''); //make sure there is nothing on the message before we continue                         
                $("#dprDialogeForm").submit();
            },
            "Cancel": function () {
                $(this).dialog("close");
            }
        }
    });

    $("a:.create, a:.edit, a:.delete").live("click", function () {

        //change the title of the dialog
        linkObj = $(this);

        var dprDialogDiv = $('#dprDialogDiv');
        var viewUrl = linkObj.attr('href');
        $.get(viewUrl, function (data) {
            dprDialogDiv.html(data);
            //validation
            var $form = $("#dprDialogeForm");
            // Unbind existing validation
            $form.unbind();
            $form.data("validator", null);
            // Check document for changes
            $.validator.unobtrusive.parse(document);
            // Re add validation with changes
            $form.validate($form.data("unobtrusiveValidation").options);
            //open dialog
            dprDialogDiv.dialog('open');
        });
        return false;
    });

});


function updateSuccess(data) {
    if (data.Success == true) {
        //notification
        $('#successmessage').html("Successfull!");
        $('#successmessage').delay(100).slideDown(400).delay(3000).slideUp(400);

        //$('#dprDialogDiv').dialog('close');
    }
    else {
        $("#update-message").html(data.ErrorMessage);
        $("#update-message").show();
    }
}
